package testPackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

/**
 * step by step 11
 * 实现拖放
 * 需执行的一系列符合事件：
 * clickAndHold(Element元素) -单击元素不释放
 * moveToElement(Element元素) -将鼠标指针移到元素的中间，无需单击
 * release(Element元素) -释放左键单击（处于按下的状态）
 * build() -生成一个复合动作
 */
public class Selenium12 {
    public static void main(String[] args) {
        String str = "D:\\\\Enviroments\\\\geckodriver-v0.26.0-win64\\\\chromedriver.exe";
        System.setProperty("webdriver.chrome.driver", str);
        WebDriver driver = new ChromeDriver();
        driver.get("https://tb.alicdn.com/snapshot/index.html");
        driver.manage().window().maximize();
        //实现拖放
        WebElement fromWebElement = driver.findElement(By.xpath("/html/body/div[4]/div[2]/div[4]/div/ul/li[5]/a/span"));
        ///html/body/div[4]/div[2]/div[4]/div/ul/li[5]/a/span
        WebElement toWebElement = driver.findElement(By.xpath("/html/body/div[4]/div[2]/div[4]/div/ul/li[12]/a/span"));
        //创建Actions类对象
        Actions builder = new Actions(driver);
        //创建复合动作
        Action dragAndDrop = builder.clickAndHold(fromWebElement)
                .moveToElement(toWebElement).release(toWebElement)
                .build();
        //执行动作
        dragAndDrop.perform();


    }
}
